package gameTest;

import game.Player;
import game.RPSEnum;
import game.Result;
import game.RockPaperScissors;

import java.util.ArrayList;
import java.util.List;

import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.AfterClass;

public class TestRockPaperScissors {
	private RockPaperScissors rps;

	@DataProvider(name = "L")
	 public Object[][] createLostData()
	 {
		return new Object [][]
		{
			{
				 RPSEnum.SCISSORS,
				 RPSEnum.ROCK
			}
		 };
	 }
	
	@Test	(dataProvider="L")
 	void testLostPlay(RPSEnum p1, RPSEnum p2) 
 	{
	 	Assert.assertEquals(rps.play(RPSEnum.valueOf(p1.toString()), 
		  				RPSEnum.valueOf(p2.toString())),Result.LOST);
 	}
	
	 @DataProvider(name = "W")
	 public Object[][] createWinData()
	 {
		return new Object [][]
		{
			 {
				 RPSEnum.PAPER,
				 RPSEnum.ROCK
			 }
		};
	 }
	 
	 @Test	(dataProvider="W")
	 	void testWinPlay(RPSEnum p1, RPSEnum p2) 
	 	{
		 	Assert.assertEquals(rps.play(RPSEnum.valueOf(p1.toString()), 
							RPSEnum.valueOf(p2.toString())),Result.WIN);
	 	}
	 
	 @DataProvider(name = "T")
	 public Object[][] createTieData()
	 {
		return new Object [][]
		{
			 {
				 RPSEnum.PAPER,
				 RPSEnum.PAPER
			 }
		 };
	 }
	 
	 @Test	(dataProvider="T")
	 	void testTiePlay(RPSEnum p1, RPSEnum p2) 
		{
		 	Assert.assertEquals(rps.play(RPSEnum.valueOf(p1.toString()), 
			  				RPSEnum.valueOf(p2.toString())),Result.TIE);
		}
	 
	 @DataProvider(name = "P1L")
	 public Object[][] createLostDataList()
	 {
		 List<RPSEnum> P1List = new ArrayList<RPSEnum>();
		 List<RPSEnum> P2List = new ArrayList<RPSEnum>();
		 
		 for(int i=0;i<20;i++)
		 {
			 P1List.add(RPSEnum.PAPER);
			 P2List.add(RPSEnum.SCISSORS);
		 }
		
		return new Object [][]
		{
			{
				 new Player(0, "p1", P1List),
				 new Player(0, "p2", P2List)
			}
		 };
	 }
	 
	 @Test	(dataProvider="P1L")
	 	void testLostPlayList(Player p1, Player p2) 
	 	{
		   Assert.assertEquals(rps.play(p1, p2),Result.LOST);
	 	}
	 
	 @DataProvider(name = "P1W")
	 public Object[][] createWinDataList()
	 {	
		 List<RPSEnum> P1List = new ArrayList<RPSEnum>();
		 List<RPSEnum> P2List = new ArrayList<RPSEnum>();
		 
		 for(int i=0;i<20;i++)
		 {
			 P1List.add(RPSEnum.ROCK);
			 P2List.add(RPSEnum.SCISSORS);
		 }
		 
		return new Object [][]
		{
			{
				 new Player(0, "p1", P1List),
				 new Player(0, "p2", P2List)
			}
		 };
		 
	 }
	 
	 @Test	(dataProvider="P1W")
	 	void testWinPlayList(Player p1, Player p2) 
	 	{
	 		Assert.assertEquals(rps.play(p1, p2),Result.WIN);
	 	}
	 
	 @DataProvider(name = "P1T")
	 public Object[][] createTieDataList()
	 {
		 List<RPSEnum> P1List = new ArrayList<RPSEnum>();
		 List<RPSEnum> P2List = new ArrayList<RPSEnum>();
		 
		 for(int i=0;i<20;i++)
		 {
			 P1List.add(RPSEnum.PAPER);
			 P2List.add(RPSEnum.PAPER);
		 }
		
		return new Object [][]
		{
			{
				 new Player(0, "p1", P1List),
				 new Player(0, "p2", P2List)
			}
		 };
	 }
	 
	 @Test	(dataProvider="P1T")
	 	void testTiePlayList(Player p1, Player p2) 
 		{
		   Assert.assertEquals(rps.play(p1, p2),Result.TIE);
	 	}
  
	 @BeforeClass
	 	void setUpClass() 
	 	{
		 	rps = new RockPaperScissors();
	 	}

	 @AfterClass
	 	public void afterClass() 
	 	{
		 	rps = null;
	 	}
}
